In [31]:
%matplotlib inline
import sys
import IPython
import sklearn
import matplotlib
import numpy as np
import pandas as pd
import scipy as sp
import matplotlib.pyplot as plt
from scipy import sparse
In [2]:
x = np.array([[1,2,3], [4,5,6]])
print('x:\n{}'.format(x))
In [4]:
# Create a 2D NumPy array with a diagonal of ones, and zeros everywhere else
eye = np.eye(4)
print('NumPy array:\n{}'.format(eye))
In [5]:
# Convert the Numpy array to a SciPy sparse matrix in CSR format
# Only the nonzero entries are stored
sparse_matrix = sparse.csr_matrix(eye)
print('Scipy sparse CSR matrix:\n{}'.format(sparse_matrix))
In [10]:
data = np.ones(4)
row_indices = np.arange(4)
column_indices = np.arange(4)
eye_coo = sparse.coo_matrix((data, (row_indices, column_indices)))
print('COO representation:\n{}'.format(eye_coo))
In [14]:
# Generate a sequence of numbers from -10 to 10 with 100 steps in between
x = np.linspace(-10, 10, 100)
# create second array using sine
y = np.sin(x)
# The plot function makes a line chart of one array against another
plt.plot(x, y, marker='x')
Out[14]:
In [17]:
# create a simple dataset of people
data = {
'Name': ['John', 'Anna', 'Peter', 'Linda'],
'Location': ['New York', 'Paris', 'Berlin', 'London'],
'Age': [24, 13, 53, 33]
}
data_pandas = pd.DataFrame(data)
data_pandas
Out[17]:
In [19]:
data_pandas[data_pandas.Age > 30]
Out[19]:
In [32]:
print("Python version: {}".format(sys.version))
print("pandas version: {}".format(pd.__version__))
print("matplotlib version: {}".format(matplotlib.__version__))
print("NumPy version: {}".format(np.__version__))
print("SciPy version: {}".format(sp.__version__))
print("IPython version: {}".format(IPython.__version__))
print("scikit-learn version: {}".format(sklearn.__version__))
In [ ]: